import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)

        toolBar =QToolBar()
        cb = QCheckBox('IsReadOnly')
        cb.stateChanged.connect(self.OnIsReadOnlyChanged)
        toolBar.addWidget(cb)  
        layout.addWidget(toolBar)

        toolBar.addWidget(QLabel('LineWrapMode:'))
        lineWrapMode = QComboBox()        
        lineWrapMode.addItems(QPlainTextEdit.LineWrapMode.__members__.keys())
        lineWrapMode.currentTextChanged.connect(self.LineWrapModeChanged)
        toolBar.addWidget(lineWrapMode)

        toolBar.addWidget(QLabel('WordWrapMode:'))
        wordWrapMode = QComboBox()        
        wordWrapMode.addItems(QTextOption.WrapMode.__members__.keys())
        wordWrapMode.currentTextChanged.connect(self.WordWrapModeChanged)
        toolBar.addWidget(wordWrapMode)

        toolBar.addWidget(QLabel('PlaceholderText:'))
        self.placeholder = QLineEdit()
        self.placeholder.editingFinished.connect(self.SetPlaceholderText)
        toolBar.addWidget(self.placeholder)

        btn = QPushButton('ShowText')
        btn.clicked.connect(self.ShowText)
        toolBar.addWidget(btn)

        self.plainTextEdit=QPlainTextEdit()
        layout.addWidget(self.plainTextEdit)

        self.setLayout(layout)
    def OnIsReadOnlyChanged(self,state):
        self.plainTextEdit.setReadOnly(state)
        self.parent.OnShowMessage(f"Set ReadOnly={state}")
    def LineWrapModeChanged(self,text):
        lineWrapMode=QPlainTextEdit.LineWrapMode[text]
        self.plainTextEdit.setLineWrapMode(lineWrapMode)
        self.parent.OnShowMessage(f'Set LineWrapMode: {lineWrapMode}')
    def WordWrapModeChanged(self,text):
        wordWrapMode=QTextOption.WrapMode[text]
        self.plainTextEdit.setWordWrapMode(wordWrapMode)
        self.parent.OnShowMessage(f'Set WordWrapMode: {wordWrapMode}')
    def SetPlaceholderText(self):
        placeholder = self.placeholder.text()
        self.plainTextEdit.setPlaceholderText(placeholder)
        self.parent.OnShowMessage(f'Set PlaceholderText: {placeholder}')
    def ShowText(self):
        self.parent.OnShowMessage(f'text: {self.plainTextEdit.toPlainText()}')
def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet